package top.ldkxingzhe.ldksettings.adapters

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Switch
import android.widget.TextView
import top.ldkxingzhe.ldksettings.R
import top.ldkxingzhe.ldksettings.entities.ComponentEntity

/**
 * Created by liangdengke on 2018/10/22.
 */
class ComponentAdapter(data: List<ComponentEntity>?) : BaseAdapter<ComponentViewHolder, ComponentEntity>(data) {

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ComponentViewHolder {
        val rootView = LayoutInflater.from(p0.context).inflate(R.layout.list_item_component, p0, false)
        return ComponentViewHolder(rootView)
    }

    override fun onBindViewHolder(p0: ComponentViewHolder, p1: Int) {
        val item = getItem(p1)
        p0.name.text = item.name
        p0.actions.text = item.actions
        p0.switch.isChecked = item.status
    }

}

class ComponentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
    val name = itemView.findViewById<TextView>(R.id.tv_name)!!
    val actions = itemView.findViewById<TextView>(R.id.tv_actions)!!
    val switch = itemView.findViewById<Switch>(R.id.sw_status)!!
}